package com.netty;

import cn.hutool.json.JSONUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MyClientHandler extends SimpleChannelInboundHandler<Object> {

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, Object obj) throws Exception {
		Channel incoming = ctx.channel();

		log.info("收到服务端的回复->{}", obj.toString());
	}

	@Override
	public void channelActive(ChannelHandlerContext ctx) {
		log.info("【Active】 [{}] is connected to the server", ctx.channel().remoteAddress());
	}

	@Override
	public void channelInactive(ChannelHandlerContext ctx) {
		log.info("client disconnet with server");
		ctx.close();
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
		log.info("client disconnect error  with server->{}", cause.getMessage());
		ctx.close();
	}
}
